Java JavaScript Python C# C C++ Go Kotlin PHP Swift R Ruby TypeScript Scala SQL Perl rust VisualBasic Matlab Julia

Abstraction in java

Abstract vs Concrete

Comparing abstract classes and concrete classes in Java

Definition

Abstract Class An abstract class is a type of class in Java that is declared by the abstract keyword. It cannot be instantiated directly, i.e., the object of such a class cannot be created directly using the new keyword. Concrete Class: A concrete class in Java is a type of subclass, which implements all the abstract methods of its super abstract class which it extends to. It also has implementations of all methods of interfaces it implements.

Modifier

Abstract Class An abstract class is declared using the abstract modifier. Concrete Class: A concrete class should not be declared using the abstract keyword, on doing so, it will also become an abstract class.

Instantiation

Abstract Class An abstract class cannot be instantiated directly, i.e., an object of such a class cannot be created directly using the new keyword. An abstract class can be instantiated either by a concrete subclass or by defining all the abstract methods along with the new statement. Concrete Class: A concrete class can be instantiated directly, using the new keyword.

Abstract Methods

Abstract Class An abstract class may or may not have an abstract method. A class containing an abstract method must also be abstract. Concrete Class: A concrete class cannot have an abstract method, because a class containing an abstract method must also be abstract.

Purpose

Abstract Class Abstract classes enable the encapsulation of common logic. They facilitate code reusability by including both concrete (implemented) and abstract (unimplemented) methods. Concrete Class: Concrete classes provide a shared implementation that derived classes can inherit. In contrast, abstract methods mandate each subclass’s implementation of specific functionality. Note : Remember, the main purpose of an abstract class is to define a common interface for its subclasses. The abstract class defines default behavior and provides default data. On the other hand, a concrete class is a class that can be used to create an object.

  📌TAGS

★Class ★ Method ★ Object ★ java ★ oops ★Abstraction ★ Abstract class ★ concrete class

Tutorials